package com.itjob.deep.listener;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.itjob.deep.bean.UserBean;

public class SessionListener implements HttpSessionListener {

	public void sessionCreated(HttpSessionEvent event) {
	}

	@SuppressWarnings("unchecked")
	public void sessionDestroyed(HttpSessionEvent event) {
		ServletContext application = event.getSession().getServletContext();
		Map<String, UserBean> users = (Map<String, UserBean>) application.getAttribute("users");
		UserBean user = (UserBean) event.getSession().getAttribute("user");
		
		users.remove(user.getUsername());
	}

}
